package com.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.dao.CourseDao;
import com.example.dao.ScoreDao;
import com.example.dao.StudentDao;
import com.example.entity.Course;
import com.example.entity.Score;
import com.example.entity.Student;
import com.example.service.AddressService;
import com.example.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * (Score)表服务实现类
 *
 * @author makejava
 * @since 2022-11-06 21:30:31
 */
@Service("scoreService")
public class ScoreServiceImpl extends ServiceImpl<ScoreDao, Score> implements ScoreService {
    @Autowired
    private CourseDao courseDao;
    @Autowired
    private StudentDao studentDao;
    @Autowired
    private AddressService addressService;

    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void test(Integer i,Boolean flag) {
        Course course = new Course();
        course.setId(i);
        course.setName("数学");
        course.setCredit(2);
        int insert = courseDao.insert(course);
        Student student = new Student();
        student.setId(i);
        student.setName("李四");
        student.setAge(10);
        student.setClasses("1班");
        int insert1 = studentDao.insert(student);
        boolean flag1= i != 4 && i != 7;
        addressService.insertAddress(i,flag1);
        if (!flag){
            throw new RuntimeException("发生错误");
        }
        Score score = new Score();
        score.setId(i);
        score.setCId(i);
        score.setSId(i);
        score.setResult(80D);
        int insert2 = baseMapper.insert(score);
    }
}

